package com.csdj.thread;

import java.util.concurrent.TimeUnit;

public class QianThread implements Runnable {
    private int balance = 10;

    public synchronized void ticket(){
        if(balance>=0){
            balance--;
        }
        try {
            TimeUnit.MILLISECONDS.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void run() {
        while (balance>0){
            ticket();
            String name = Thread.currentThread().getName();
            if("黄牛党".equals(name)){
                break;
//                return;
            }
        }
    }
}
